package servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.*;

/**
 * Servlet implementation class NoteServlet
 */
@WebServlet("/NoteServlet")
public class NoteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public NoteServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	public void init() {

	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		HttpSession session = request.getSession(true);

		String snume = (String) session.getAttribute("studNume");

		// String mnume = (String) session.getAttribute("matNume");

		PrintWriter out = response.getWriter();

		out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 "
				+ "Transitional//EN\">");
		out.println("<html>");
		
		out.println("<head>");
		out.println("<title>" + "Main page!" + "</title>");
		out.println("</head>");
		out.println("<body bgcolor=\"#F3FBFE\">");
		out.println("<br>");
		out.println(snume);
		// out.println(mnume);
		out.println("<br>Spune materia :");
		out.println("<form method=\"get\" action=\"/ServletTest/NoteServletResult\">");
		out.println("<input name=\"materia\" type=\"text\">");
		out.println("<input type=\"submit\" value=\"Enter\"></form>");

		/*
		 * if (request.getParameter("materia") != null) {
		 * 
		 * }
		 */

		out.println("<form method=\"GET\" action=\"/ServletTest/DispatcherServlet\"> ");
		out.println("<br><br><input type=\"submit\" name=\"main\" value=\"Main\"></form>");
		out.println("</body>");
		out.println("</html>");

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
